package com.nineclock.system.controller;

import com.nineclock.api.system.SysUserControllerApi;
import com.nineclock.common.entity.Result;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.system.dto.SysRegisterDTO;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.pojo.SysUser;
import com.nineclock.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class SysUserController implements SysUserControllerApi {

    @Autowired
    private SysUserService sysUserService;

    @Override
    @GetMapping("/query")
    public Result<SysUserDTO> query(@RequestParam("username") String username) {
        SysUser sysUser = sysUserService.query(username);
        SysUserDTO userDTO = BeanHelper.copyProperties(sysUser, SysUserDTO.class);
        return Result.success(userDTO);
    }


    @Override
    @PostMapping("/register")
    public Result<Long> register(SysRegisterDTO registerDTO) {
        Long userId = sysUserService.register(registerDTO);
        return Result.success(userId);
    }
}
